<%@ page import="java.util.Properties" %>
<%@ page import="javax.mail.internet.MimeMessage" %>
<%@ page import="javax.mail.internet.InternetAddress" %>
<%@ page import="javax.mail.*" %><%--
  Created by IntelliJ IDEA.
  User: Think
  Date: 2024/7/24
  Time: 下午3:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<%
    String result;
    String to = "1156678791@qq.com";
    String host = "smtp.qq.com";
    String form = "2802525702@qq.com";
    Properties properties = System.getProperties();
    // 设置邮件服务器
    properties.setProperty("mail.smtp.host", host);
    properties.put("mail.smtp.auth", "true"); // 需要验证
    properties.put("mail.debug", "true");
    Session mailSession = Session.getInstance(
            properties,
            new javax.mail.Authenticator() {
                protected PasswordAuthentication getPasswordAuthentication() {
                    return new PasswordAuthentication("2802525702@qq.com","zds172731123");
                }
            }
    );
    try {
        MimeMessage message = new MimeMessage(mailSession);
        message.setFrom(new InternetAddress(form));
        message.setRecipients(Message.RecipientType.TO, String.valueOf(new InternetAddress(to)));
        message.setSubject("This is the Subject Line!");
        message.setText("This is the Body");
        Transport.send(message);
        result = "Send message success!";
    }catch (MessagingException mex){
        mex.printStackTrace();
        result = "Error:unable to send message";
    }
%>
<head>
    <title>发送一封简单的邮件</title>
</head>
<body>
<p align ="center">
    <%
        out.print("Result :" + result +"\n");
    %>

</p>
</body>
</html>
